package com.source.lightfowl.person.dao;

import com.source.lightfowl.person.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
public interface RoleDao extends JpaRepository<Role,String>{
    List<Role> findByRnameLike(String rname);

    @Query(
            value = "select * from role where rid=?",
            nativeQuery = true
    )
    Role findByRid(String role);

    @Query(
            value = "DELETE FROM role WHERE rid=?1",
            nativeQuery = true
    )
    void deleteByRid(String rid);

    @Query(
            value = "update role set rname=?2 where rid=?1",
            nativeQuery = true
    )
    @Modifying
    void updateRolename(String id, String name);
    @Query(
            value = "select rid from role where rname=?",
            nativeQuery = true
    )
    String findRidByname(String name);
}
